//
//  SecondViewController.m
//  UITableViewHomework
//
//  Created by dllo on 16/7/26.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "SecondViewController.h"
#import "City.h"
#import "Distric.h"
#import "ThirdViewController.h"

#define kTableView @"resue"
@interface SecondViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong)UITableView *tableView;
@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
      _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
      [self.view addSubview:_tableView];
      _tableView.delegate = self;
      _tableView.dataSource = self;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

      return self.province.arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableView];
      if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kTableView];
            
      }
      City *city = self.province.arr[indexPath.row];
      NSArray *nameArr = [city.name componentsSeparatedByString:@" "];
      cell.textLabel.text = nameArr[2];
      cell.detailTextLabel.text = nameArr.lastObject;
      return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
      ThirdViewController *third = [[ThirdViewController alloc]init];
      [self.navigationController pushViewController:third animated:YES];
      third.city = self.province.arr[indexPath.row];
}

@end
